package metrixIMP;

import metrixIMP.metrixSquare;


public class test
{
	public interface TypeCanbeAddup
	{
		// just return the addup result value, no change of selfdata
		public TypeCanbeAddup doAddup(TypeCanbeAddup addv);
	}
	
	public static<T extends TypeCanbeAddup> T doArraryAddup(T[] inputArr)
	{
		if(0 == inputArr.length)
		{
			return null;
		}
		T valueReturn= inputArr[0];
		for(int loop=1; loop<inputArr.length; ++loop)
		{
			valueReturn = (T) inputArr[loop].doAddup(valueReturn);
		}
		
		return valueReturn;
	}
	
	public class theInt implements TypeCanbeAddup
	{
		private int selfv;
		public theInt(theInt thev)
		{
			this.selfv = thev.selfv;
		}
		public theInt(int thev)
		{
			this.selfv = thev;
		}
		public TypeCanbeAddup doAddup(TypeCanbeAddup addv)
		{
			if(addv instanceof theInt)
			{
				int tmp = this.selfv + ((theInt)addv).selfv;
				return (TypeCanbeAddup)(new theInt(tmp));
			}
			else
			{
				return null;
			}
		}
	}
	
	public class thefloat implements TypeCanbeAddup
	{
		private float selfv;
		public thefloat(theInt thev)
		{
			this.selfv = thev.selfv;
		}
		public thefloat(float thev)
		{
			this.selfv = thev;
		}
		public TypeCanbeAddup doAddup(TypeCanbeAddup addv)
		{
			if(addv instanceof thefloat)
			{
				float tmp = this.selfv + ((thefloat)addv).selfv;
				return (TypeCanbeAddup)(new thefloat(tmp));
			}
			else
			{
				return null;
			}
		}
	}
	
	public static void main(String[] args)
	{
		System.out.println("in zjn java test");
		int a=512;
		if((a & (a-1)) == 0)
		{
			System.out.println("power of 2");
		}
		else
		{
			System.out.println("not power of 2");
		}
		System.exit(0);
		
		test testobj = new test();
		
		theInt[] testarrar = new theInt[4];
		testarrar[0] = testobj.new theInt(11);
		testarrar[1] = testobj.new theInt(12);
		testarrar[2] = testobj.new theInt(13);
		testarrar[3] = testobj.new theInt(14);
		
		theInt testaddv = test.doArraryAddup(testarrar);
		System.out.println("in zjn java test"+testaddv.selfv);
		
		thefloat[] testarrarf = new thefloat[4];
		testarrarf[0] = testobj.new thefloat(11.3f);
		testarrarf[1] = testobj.new thefloat(12.3f);
		testarrarf[2] = testobj.new thefloat(13.3f);
		testarrarf[3] = testobj.new thefloat(14.3f);
		
		thefloat testaddvf = test.doArraryAddup(testarrarf);
		System.out.println(testaddvf.selfv);
		
		
		System.exit(0);
		
		double[] mm1 = new double[32];
		double[] mm2 = new double[32];
		
		for(int i = 0; i<mm1.length; ++i)
		{
			mm1[i] = i;
			mm2[i] = 16-i;
		}
		
		metrixSquare zmm1 = new metrixSquare(4, mm1);
		metrixSquare zmm2 = new metrixSquare(5, mm2);
		
		zmm1.metrixShow();
		zmm2.metrixShow();
	}	
}
